package com.guigu.qingcheng.service_user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.qingcheng.pojo.user.TbProvinces;
import com.guigu.qingcheng.service_user.mapper.TbProvincesMapper;
import com.guigu.qingcheng.service_user.service.TbProvincesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 省份信息表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@Service
public class TbProvincesServiceImpl extends ServiceImpl<TbProvincesMapper, TbProvinces> implements TbProvincesService {
    @Autowired
    private TbProvincesService provincesService;

    @Override
    public Page<TbProvinces> findPage(Map<String, Object> searchMap, Integer page, Integer size) {
        Page<TbProvinces> page1=new Page<TbProvinces>(page,size);
        QueryWrapper<TbProvinces> wrapper=queryWrapper(searchMap);
        IPage<TbProvinces> iPage = provincesService.page(page1, wrapper);
        return page1;
    }

    /**
     * 高级组合查询封装对象
     * @param searchMap
     * @return
     */
    public QueryWrapper<TbProvinces> queryWrapper(Map<String, Object> searchMap){
        QueryWrapper<TbProvinces> wapper = new QueryWrapper<TbProvinces>();
        if(searchMap != null){
            if(searchMap.get("provinceid") != null && !"".equals(searchMap.get("provinceid")))
                wapper.eq("provinceid",searchMap.get("provinceid"));
            if(searchMap.get("province") != null && !"".equals(searchMap.get("province")))
                wapper.like("province", "%" + searchMap.get("province") + "%");
        }
        return wapper;
    }

}
